using UnityEngine;
using System.Collections;

public class CharacterMenu : MonoBehaviour {
	
	public GameObject infoPanelHolder;
	
	public GameObject[] infoPanelPrefabs;
	
	GameObject currentInfoPanel;
	string currentInfoPanelType;

	// Use this for initialization
	void Start () {
		GameObject g = Instantiate(infoPanelPrefabs[0]) as GameObject;
		g.transform.parent = infoPanelHolder.transform;
		g.transform.localScale = Vector3.one;
		g.transform.localPosition = Vector3.zero;
		currentInfoPanel = g;
		currentInfoPanelType = infoPanelPrefabs[0].name;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OpenInfoPanelByIndex(int i)
	{
		if(currentInfoPanelType != infoPanelPrefabs[i].name)
		{
			if(currentInfoPanel != null)
				Destroy(currentInfoPanel);
			
			GameObject g = Instantiate(infoPanelPrefabs[i]) as GameObject;
			g.transform.parent = infoPanelHolder.transform;
			g.transform.localScale = Vector3.one;
			g.transform.localPosition = Vector3.zero;
			currentInfoPanel = g;
			currentInfoPanelType = infoPanelPrefabs[i].name;
		}
	}
	
	void OpenGeneralPanel()
	{
		Debug.Log("Opened General Info");
		OpenInfoPanelByIndex(0);
	}
	
	void OpenCombatPanel()
	{
		Debug.Log("Opened Combat Info");
		OpenInfoPanelByIndex(1);
	}
	
	void OpenAbilityPanel()
	{
		Debug.Log("Opened Ability Info");
		OpenInfoPanelByIndex(2);
	}
	
	void OpenInventoryPanel()
	{
		Debug.Log("Opened Inventory Info");
		OpenInfoPanelByIndex(3);
	}
	
	void OpenMagicPanel()
	{
		Debug.Log("Opened Magic Info");
		OpenInfoPanelByIndex(4);
	}
	
	void OpenHistoryPanel()
	{
		Debug.Log("Opened History Info");
		OpenInfoPanelByIndex(5);
	}
	
	void SaveAndExit()
	{
		SheetManager.SaveActiveCharacter(false);
		Destroy(gameObject);
	}
}
